package pers.xhh.frontapi.controller;

import com.alipay.api.AlipayApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.xhh.frontapi.common.Mi;
import pers.xhh.frontapi.config.AlipayTemplate;
import pers.xhh.frontapi.entity.vo.pay.PayOrderVo;
import pers.xhh.frontapi.service.PayService;

import java.io.IOException;

/**
 * @author wei-xhh
 * http://127.0.0.1:8848/memberOrder.html?charset=utf-8&out_trade_no=zfb_1336953414311047169&method=alipay.trade.page.pay.return&total_amount=3998.00&sign=F6%2BN9c2WO9gCAbMJv%2BYdWP4hAp6LcK9gEwwBjMuMmYTHsH3EV63g0oVBbUeY6YtXhwhybH4bveYkqwXpucr0WtiE3LAfcvnxH5sRYNFljHwo4gzjP0eLECHcxw7gH5YiQ%2FrXs5BRHxRlx5ZVQvkIjznXv0DEapbtxhRAq3lyNVqF%2BpjcceOvlN4kXZmiP3cYyBLr%2BAgj0NAHeVuC0oxdr8gPuMmczCPd3u0p319RI36%2Fwea77bw7BHciAefvgO4LtMkqO%2FtZoirYGgfiNVti%2Fw5fUeEUsshDRSwSW%2FXtzokcd0QBwan4Phk2sR54TYAbXxTCICgw%2Bi7nPmLR%2BHaqdQ%3D%3D&trade_no=2020121022001444920501115246&auth_app_id=2016102600761204&version=1.0&app_id=2016102600761204&sign_type=RSA2&seller_id=2088102181077449&timestamp=2020-12-10+16%3A41%3A36
 * @date 2020-12-08
 */
@CrossOrigin
@RestController
@RequestMapping("/mi/api")
public class PayController {

    @Autowired
    PayService payService;

    @Autowired
    AlipayTemplate alipayTemplate;

    @GetMapping(value = "/pay/order", produces = "text/html")
    public String payOrder(@RequestParam("orderSn") String orderSn,
                         @RequestParam("payPrice") String payPrice,
                         @RequestParam(name = "body", required = false) String body) throws AlipayApiException, IOException {
        PayOrderVo payOrderVo = new PayOrderVo();
        payOrderVo.setOrderSn(orderSn);
        payOrderVo.setPayPrice(payPrice);
        payOrderVo.setBody(body);
        return payService.payOrder(payOrderVo);

    }

    @GetMapping("/pay/success")
    public Mi paySuccess(){
        System.out.println("支付成功了！");
        // TODO 修改订单状态,更新库存
        boolean b = payService.success();

        return null;
    }
}
